<template>
  <common_print_dialog ref="common_print_dialog" businessType="BOARD" v-bind="$attrs" v-on="$listeners" :tableModel="[
    { key: 'boardNo', label: 'label_package_collection_no', 'min-width': 120, 'show-overflow-tooltip': true, },
  ]" singlePrintNumber :templateVisiable="!thirdParty" :urlGetFun="urlGetFun" :printUrl="printUrl"
    :printHandler="printHandler" :previewUrl="previewUrl" :previewHandler="previewHandler" />
</template>

<script>
import common_print_dialog from './common_print_dialog.vue'

export default {
  components: { common_print_dialog },
  props: {
  },
  data() {
    return {
      previewUrl: "/wms-api/print/PrintRpc/boardPreview.json",
      printUrl: "",
      thirdParty: false,
    }
  },
  methods: {
    urlGetFun(row) {
      if (this.thirdParty) {
        return { url: row.filePath, oss: true }
      } else {
        return null
      }
    },
    previewHandler(data, row) {
      data.boardNo = row.boardNo;
      data.printerName = 'none'
      data.clientName = 'none'
      return data
    },
    printHandler(data, list) {
      if (this.thirdParty) {
        return {
          paramList: list.map(it => {
            return {
              clientId: data.clientName,
              printerName: data.printerName,
              printCount: data.printNumSum,
              fileName: it.fileName,
              fileType: this.$reg.FileExt(it.filePath),//data.fileType,
              labelOssPath: it.filePath,
            }
          })
        }
      } else {
        data.boardPrintDataList = list.map(it => (
          {
            boardNo: it.boardNo,
            printNum: it.printNum
          }
        ))
      }

      return data
    },
    show(rows, option,) {
      option = Object.assign({},option)
      let thirdParty = !!(option && option.thirdParty)
      this.thirdParty = !!thirdParty
      if (!!thirdParty) {
        this.printUrl = "/wms-api/outbound/OutboundBoxPackageRpc/printPdfList.json"
      } else {
        this.printUrl = "/wms-api/print/PrintRpc/boardPrint.json"
      }
      option.url = this.printUrl
      if (this.thirdParty) {
        option.title = this.$tt('label_print_any', { type: this.$t('label_third_party_collect_pack_mark') })
      }

      this.$refs.common_print_dialog.show(rows, option)
    },
    setDefaultOption(...params) {
      this.$refs.common_print_dialog.setDefaultOption(...params)
    },

    printDefaultOption(params,) {
      let thirdParty = !!(params && params.thirdParty)
      this.thirdParty = !!thirdParty
      if (!!thirdParty) {
        params.url = "/wms-api/outbound/OutboundBoxPackageRpc/printPdfList.json"
      } else {
        params.url = "/wms-api/print/PrintRpc/boardPrint.json"
      }
      this.$refs.common_print_dialog.printDefaultOption(params)
    },
    removeDefaultOption(...params) {
      this.$refs.common_print_dialog.removeDefaultOption(...params)
    },
  }
}
</script>
